﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ref和out关键字的使用
{
    class Program
    {
        static void Main(string[] args)
        {
            //int i1 = 10,
            //    i2 = 20;
            //Console.WriteLine("original values: i1 = {0}, i2 = {1}",i1,i2);
            ////用ref之前必须给变量赋值
            //Swap(ref i1,ref i2);   //传递引用,给函数传递参数的时候也要加ref
            //Console.WriteLine("values after swap:i1 = {0}, i2 = {1}", i1, i2);
            bool b;
            int i = Parse("一",out b);

            if (b)
            {
                Console.WriteLine("转换成功！");
            }
            else
            {
                Console.WriteLine("转换不成功！");
            }

            Console.ReadKey();
        }

        //static void Swap(ref int i1,ref int i2) //reference -> ref
        //{
        //    int temp = i1;
        //    i1 = i2;
        //    i2 = temp;
        //}

        static int Parse(string num, out bool function_status)
        {
            if ("一" == num)
            {
                function_status = true;
                return 1;
            }
            if ("二" == num)
            {
                function_status = true;
                return 2;
            }
            else
            {
                function_status = false;
                return -1;
            }
        }
    }
}
